前情提要
Line Notify API 串接實作-前置作業
Line Notify API 串接實作(一)-取得access token
Line Notify API 串接實作(二)-推播訊息
Line Notify 提供了我們可以去查詢使用者的token狀態和撤銷使用者的token功能,這些都可以幫助我們更方便的設置Notify設定。
GET https://notify-api.line.me/api/status
請求參數-header
回應參數-header
回應參數-body
postman
checkTokenStatus方法
public static LineNotifyCheckResponse checkTokenStatus(String token) {
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(token);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(headers);
ResponseEntity<LineNotifyCheckResponse> lineNotifyCheckResponse =
restTemplate.exchange(LineNotifyUrl.TOKEN_STATUS_CHECK.getUrl(),
LineNotifyUrl.TOKEN_STATUS_CHECK.getHttpMethod(),
entity,
LineNotifyCheckResponse.class);
if(!lineNotifyCheckResponse.getStatusCode().equals(HttpStatus.OK)) {
throw new LineNotifyUtilException(
LineNotifyErrorEnum.TOKEN_STATUS_CHECK_ERROR.getError(),
LineNotifyErrorEnum.TOKEN_STATUS_CHECK_ERROR.getMessage()
);
}
return lineNotifyCheckResponse.getBody();
}
LineNotifyCheckResponse
@Data
public class LineNotifyCheckResponse {
private Integer status;
private String message;
private String targetType;
private String target;
}
POST https://notify-api.line.me/api/revoke
請求參數-header
回應參數-header
回應參數-body
postman
Line訊息彈出
revoke方法
public static LineNotifyRevokeResponse revoke(String token) {
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(token);
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<>(headers);
ResponseEntity<LineNotifyRevokeResponse> lineNotifyRevokeResponse =
restTemplate.exchange(LineNotifyUrl.TOKEN_REVOKE.getUrl(),
LineNotifyUrl.TOKEN_REVOKE.getHttpMethod(),
entity,
LineNotifyRevokeResponse.class);
if(!(lineNotifyRevokeResponse.getStatusCode().equals(HttpStatus.OK))&&
!(lineNotifyRevokeResponse.getStatusCode().equals(HttpStatus.UNAUTHORIZED))
) {
throw new LineNotifyUtilException(
LineNotifyErrorEnum.TOKEN_REVOKE_FAIL.getError(),
LineNotifyErrorEnum.TOKEN_REVOKE_FAIL.getMessage()
);
}
return lineNotifyRevokeResponse.getBody();
}
LineNotifyRevokeResponse物件
@Data
public class LineNotifyRevokeResponse {
private String status;
private String message;
}
好了,那我們Line Notify的講解到此告一段落,之後有機會再來實作看看Line其他有趣的API